﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using Limilabs.Mail;
using Limilabs.Mail.Headers;
using Limilabs.Client.SMTP;


namespace PennApps
{
    public partial class TransportService
    {
        private static string userNameEmail = "momapp2013@gmail.com";
        private static string password = "liangluo";
        private static string infoDestinationEmail = "momapp2013@gmail.com";
        private static string commandDestinationEmail = "momapp2013commands@gmail.com";

        public static void Send(ProcessPerformanceInformation[] performanceInfoArray)
        {
            MailBuilder builder = new MailBuilder();
            builder.From.Add(new MailBox(userNameEmail));
            builder.To.Add(new MailBox(infoDestinationEmail));
            builder.Subject = "INFO";
            builder.Text = (new PerformanceInfoToTextConversionEngine()).Convert(performanceInfoArray);
            IMail email = builder.Create();
            // Send the message
            using (Smtp smtp = new Smtp())
            {
                smtp.ConnectSSL("smtp.gmail.com",465);    // or ConnectSSL for SSL
                smtp.UseBestLogin(userNameEmail, password); // remove if not needed
                smtp.SendMessage(email);
                smtp.Close();
            }
            
        }

        public static void SendCommand( Command command)
        {
            PerformanceInfoToTextConversionEngine converter = new PerformanceInfoToTextConversionEngine();
            string commandText = converter.CommandConvertBack(command);
            MailBuilder builder = new MailBuilder();
            builder.From.Add(new MailBox(userNameEmail));
            builder.To.Add(new MailBox(commandDestinationEmail));
            builder.Subject = "COMMAND";
            builder.Text = commandText;
            IMail email = builder.Create();
            // Send the message
            using (Smtp smtp = new Smtp())
            {
                smtp.ConnectSSL("smtp.gmail.com", 465);    // or ConnectSSL for SSL
                smtp.UseBestLogin(userNameEmail, password); // remove if not needed
                smtp.SendMessage(email);
                smtp.Close();
            }

        }

        /*
        public static void Send(ProcessPerformanceInformation[] performanceInfoArray)
        {
            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
            message.To.Add("momapp2013@gmail.com");
            message.Subject = "INFO";
            message.From = new System.Net.Mail.MailAddress("momapp2013@gmail.com");
            message.Body = (new PerformanceInfoToTextConversionEngine()).Convert(performanceInfoArray);
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com", 25);
            NetworkCredential credential = new NetworkCredential("momapp2013@gmail.com", "liangluo");
            smtp.Credentials = credential;
            smtp.EnableSsl = true;
            smtp.Send(message);
        }
        */

    }
}
